package jianzhi_offer;

public class _16_树的子结构 {
	public boolean HasSubtree(TreeNode root1, TreeNode root2) {
		if(root2 == null) return false;
		return help(root1,root2);
	}

	public boolean help(TreeNode root1, TreeNode root2) {
		if (root1 == null) {
			if (root2 == null)
				return true;
			return false;
		}
		if (root2 == null)
			return true;
		if (root1.val != root2.val)
			return false;
		if (help(root1.left, root2.left) && help(root1.right, root2.right))
			return true;
		return help(root1.left, root2) || help(root1.right, root2);
	}
}
